package lab1;

public class EulerMethodModified {
    public static void main(String[] args) {

        System.out.println("Metoda Euler Modificata: h = 0.1 || n = 10");
        eulerMethodModified(1, 1, 0.1, 10);
        System.out.println("Metoda Euler Modificata: h = 0.2 || n = 5");
        eulerMethodModified(1, 1, 0.2, 5);
    }

    private static void eulerMethodModified(double x0, double u0, final double h, final int n) {
        for (int i = 0; i <= n; i++) {
            double newX = x0 + h;
            double uStelat = u0 + h * (-3 * u0 * u0 * x0 * x0);
            double const1 = -3 * uStelat * uStelat * newX * newX;
            double newU = u0 + (h / 2) * (-3 * u0 * u0 * x0 * x0 + const1 );
            System.out.println("NewU : " + newU);
            x0 = newX;
            u0 = newU;
        }
    }
}
